/**   
 * @Title: RadioTag.java
 * @Package com.knight.canting.core.web.taglib
 * @Description: TODO
 * @author Yi Xiaoping <thinker1013@163.com>
 * @date 2015年12月7日 上午9:30:50
 * @version V1.0   
 *//*

package com.fas.core.web.taglib;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;

import com.knight.canting.core.constant.Constants;
import com.knight.canting.core.constant.Keys;
import com.knight.canting.core.util.datadic.DataDic;
import com.knight.canting.core.util.datadic.DataDicKit;
import com.knight.canting.system.model.LoginUser;

*//**
 * 
 *
 * @Copyright: Copyright (c) 2015 Knight
 * @anthor yixiaoping<thinker1013@163.com>
 * @since 2015年12月7日 上午9:30:50
 * @version V1.0
 *//*

public class RadioTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	private Object list;
	private String name;
	private String value;
	private String listKey;
	private String listValue;

	public List<DataDic> getDataDicList(Long cropid) {
		return DataDicKit.me().getDatadicByGroupTag((String) list, cropid);
	}

	@Override
	public int doStartTag() throws JspException {
		Long corpid = Constants.SUPER_CORPID;
		LoginUser loginUser =(LoginUser)this.pageContext.getSession().getAttribute(Keys.LOGIN_USER);
		corpid = loginUser.getCorpid();
		
		JspWriter out = pageContext.getOut();
		StringBuffer selectHtml = new StringBuffer();
		try{
		        if (list instanceof String) {
		        	String definition = (String) list;
		        	if (StringUtils.isNotBlank(definition) && (definition.startsWith(DataDicKit.me().getDictPrefix()))){
		        		
		        		List<DataDic> selectItems = new ArrayList<DataDic>();
		        		String selectText = DataDicKit.me().getDictItemNameByCode(definition, value,corpid);
		        		
		        		List<DataDic> translateList = this.getDataDicList(corpid);
		        		//如果不允许为空，则默认显示第一个选项
		        		if( translateList != null && StringUtils.isBlank(selectText)){//默认选择第一项
		        		    DataDic defaultItem = translateList.get(0);
		        			if(defaultItem!=null){
		        				selectText = defaultItem.getName();
				        	    value = defaultItem.getCode();
		        			}
	        			}
		        		selectItems.addAll(translateList);
		        		
		        		for(DataDic item : selectItems){
		        			if(item.getName().equals(selectText)){
		        				selectHtml.append("<label class=checkbox-inline>").append("<input type='radio'  name='"+name+"' value='"+item.getCode()+"' checked/>&nbsp;&nbsp;"+item.getName()+"</label>");
		        			}else{
		        				selectHtml.append("<label class=checkbox-inline>").append("<input type='radio'  name='"+name+"' value='"+item.getCode()+"' />&nbsp;&nbsp;"+item.getName()+"</label>");
		        			}
		        		}
		    		}
		        }
		        
		        out.print(selectHtml.toString());
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return super.doStartTag();
	}

	public Object getList() {
		return list;
	}

	public void setList(Object list) {
		this.list = list;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getListKey() {
		return listKey;
	}

	public void setListKey(String listKey) {
		this.listKey = listKey;
	}

	public String getListValue() {
		return listValue;
	}

	public void setListValue(String listValue) {
		this.listValue = listValue;
	}

}
*/